<template>
  <div class="bg">
    <!-- 头部 -->
    <Header title="运维管理—巡检内容"></Header>

    <!-- 搜索栏 -->
    <section class="search_bar">
      <LSelect label="设备类型" :value="type" :options="option1" @selected-event="getNewSelected"></LSelect>
      <LInput label="内容名称" v-model="name" style="margin-left: 20px"></LInput>
      <LButton label="+新增" style="margin-left: 16px" @click="repairDialog = true"></LButton>
      <LButton label="查询数据" style="margin-left: 16px"></LButton>
      <LButton label="重置条件" style="margin-left: 16px" @click="clearSelected"></LButton>
    </section>
    <!-- 表格 -->
    <el-table :data="tData" style="width: 100%" border>
      <el-table-column prop="a" label="巡检内容编码" />
      <el-table-column prop="b" label="巡检内容名称" />
      <el-table-column prop="c" label="设备分类" />
      <el-table-column prop="d" label="备注" />
      <el-table-column prop="e" label="创建时间" />
      <el-table-column prop="f" label="创建人" />
      <el-table-column label="操作" width="220">
        <template #default>
          <el-button type="success" size="mini" @click="repairDialog2 = true">查看</el-button>
          <el-button type="primary" size="mini" @click="repairDialog3 = true">编辑</el-button>
          <el-button type="danger" size="mini" @click="del">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 弹出框：新增 -->
    <div v-dialogdrag>
      <el-dialog v-model="repairDialog" title="新增" width="50%" @close="repairDialogClose">
        <div class="dialog-border">
          <el-form label-width="100px" :model="repairForm" ref="repairFormRef" :rules="repairFormRules" size="small">
            <div class="row-1">
              <el-form-item label="内容编码" prop="no" style="width:100%">
                <el-input v-model="repairForm.no"></el-input>
              </el-form-item>
              <el-form-item label="内容名称" prop="no" style="width:100%">
                <el-input v-model="repairForm.no"></el-input>
              </el-form-item>
            </div>
            <div class="row-1">
              <el-form-item label="设备类型" prop="type" style="width:100%">
                <el-select v-model="repairForm.type" filterable>
                  <el-option label="冷水机组" value="1"></el-option>
                  <el-option label="冷水机组2" value="2"></el-option>
                </el-select>
              </el-form-item>
            </div>

            <div style="padding: 0 2vw 0 0">
              <el-form-item label="备注" prop="mark" style="width:100%">
                <el-input v-model="repairForm.mark" type="textarea" :rows="1"></el-input>
              </el-form-item>
            </div>
          </el-form>
          <div class="dialog-border-padding">
            <div style="padding: 1vh 0;text-align:center">已选步骤</div>
            <div style="position:relative">
              <el-button type="primary" size="mini" style="position:absolute;right:0vw;bottom:0.5vh" @click="repairDialog1=true">增加</el-button>
            </div>
            <el-table :data="tableData" style="width: 100%" border :default-sort="{ prop: 'b', order: 'ascending' }">
              <el-table-column prop="b" label="步骤编码" />
              <el-table-column prop="c" label="步骤名称" />
              <el-table-column prop="d" label="参考值" />
              <el-table-column prop="e" label="报警关系" />
              <el-table-column label="操作" width="80">
                <template #default>
                  <el-button type="danger" size="mini">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>

        <template #footer>
          <span class="dialog-footer">
            <el-button type="primary" size="mini" @click="repairSureBtn">确定</el-button>
            <el-button type="info" size="mini" @click="repairDialog = false">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>

    <!-- 弹出框里的弹框1：步骤列表 -->
    <div v-dialogdrag class="pop-2">
      <el-dialog v-model="repairDialog1" title="步骤列表" width="50%" @close="repairDialog1Close()" :rules="repairForm1Rules">
        <el-form ref="repairForm1Ref" :model="repairForm1" label-width="50px" size="small">
          <el-form-item label="搜索" prop="search" style="width: 50%">
            <el-input v-model="repairForm1.search"></el-input>
          </el-form-item>
        </el-form>
        <el-table :data="subTable1" style="width: 100%" border ref="subTable1Ref" @selection-change="subTable1Selected" :default-sort="{prop:'b',order:'ascending'}">
          <el-table-column type="selection" width="35" />
          <el-table-column prop="a" label="设备分类" />
          <el-table-column prop="b" label="编码" />
          <el-table-column prop="c" label="名称" />
          <el-table-column prop="d" label="参考值" />
          <el-table-column prop="e" label="报警关系" />
        </el-table>
        <el-pagination small background layout="prev, pager, next" :total="200000">
        </el-pagination>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="primary" size="mini" @click="repairDialog1SureBtn">确定</el-button>
            <el-button type="info" size="mini" @click="repairDialog1CalcBtn()">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>

    <!-- 弹出框：查看 -->
    <div v-dialogdrag>
      <el-dialog v-model="repairDialog2" title="查看" width="50%" @close="repairDialog2Close">
        <div class="dialog-border">
          <el-form label-width="100px" :model="repairForm2" ref="repairForm2Ref" :rules="repairForm2Rules" size="small">
            <div class="row-1">
              <el-form-item label="内容编码" prop="no" style="width:100%">
                <el-input v-model="repairForm2.no" readonly></el-input>
              </el-form-item>
              <el-form-item label="内容名称" prop="no" style="width:100%">
                <el-input v-model="repairForm2.no" readonly></el-input>
              </el-form-item>
            </div>
            <div class="row-1">
              <el-form-item label="设备类型" prop="type" style="width:100%">
                <el-input v-model="repairForm2.type" filterable>
                </el-input>
              </el-form-item>
            </div>
            <div style="padding: 0 2vw 0 0">
              <el-form-item label="备注" prop="mark" style="width:100%">
                <el-input v-model="repairForm2.mark" type="textarea" :rows="1" readonly></el-input>
              </el-form-item>
            </div>
          </el-form>
          <div class="dialog-border-padding">
            <div style="padding: 1vh 0;text-align:center">已选步骤</div>
            <el-table :data="tableData2" style="width: 100%" border :default-sort="{ prop: 'b', order: 'ascending' }">
              <el-table-column prop="b" label="步骤编码" />
              <el-table-column prop="c" label="步骤名称" />
              <el-table-column prop="d" label="参考值" />
              <el-table-column prop="e" label="报警关系" />
              <el-table-column label="操作" width="80">
                <template #default></template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="info" size="mini" @click="repairDialog2 = false">关闭</el-button>
          </span>
        </template>
      </el-dialog>
    </div>

    <!-- 弹出框：编辑 -->
    <div v-dialogdrag>
      <el-dialog v-model="repairDialog3" title="新增" width="50%" @close="repairDialog3Close">
        <div class="dialog-border">
          <el-form label-width="100px" :model="repairForm3" ref="repairForm3Ref" :rules="repairForm3Rules" size="small">
            <div class="row-1">
              <el-form-item label="内容编码" prop="no" style="width:100%">
                <el-input v-model="repairForm3.no"></el-input>
              </el-form-item>
              <el-form-item label="内容名称" prop="no" style="width:100%">
                <el-input v-model="repairForm3.no"></el-input>
              </el-form-item>
            </div>
            <div class="row-1">
              <el-form-item label="设备类型" prop="type" style="width:100%">
                <el-select v-model="repairForm3.type" filterable>
                  <el-option label="冷水机组" value="1"></el-option>
                  <el-option label="冷水机组2" value="2"></el-option>
                </el-select>
              </el-form-item>
            </div>
            <div style="padding: 0 2vw 0 0">
              <el-form-item label="备注" prop="mark" style="width:100%">
                <el-input v-model="repairForm3.mark" type="textarea" :rows="1"></el-input>
              </el-form-item>
            </div>
          </el-form>
          <div class="dialog-border-padding">
            <div style="padding: 1vh 0;text-align:center">已选步骤</div>
            <div style="position:relative">
              <el-button type="primary" size="mini" style="position:absolute;right:0vw;bottom:0.5vh" @click="repairDialog1=true">增加</el-button>
            </div>
            <el-table :data="tableData" style="width: 100%" border :default-sort="{ prop: 'b', order: 'ascending' }">
              <el-table-column prop="b" label="步骤编码" />
              <el-table-column prop="c" label="步骤名称" />
              <el-table-column prop="d" label="参考值" />
              <el-table-column prop="e" label="报警关系" />
              <el-table-column label="操作" width="80">
                <template #default>
                  <el-button type="danger" size="mini">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="primary" size="mini" @click="repairSure3Btn">确定</el-button>
            <el-button type="info" size="mini" @click="repairDialog3 = false">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>

  </div>
</template>

<script>
import Header from '@/components/Header'
import moment from "moment";
import LInput from "../../../components/LInput.vue";
import LDateTimeSelect2 from "../../../components/LDateTimeSelect2.vue";
import LButton from "../../../components/LButton.vue";
import LSelect from "@/components/LSelect.vue";

export default {
  components: {
    Header,
    LInput,
    LDateTimeSelect2,
    LButton,
    LSelect,
  },
  data() {
    return {
      name: "",
      type: "1",
      option1: [
        {
          value: "1",
          label: "全部",
        },
        {
          value: "2",
          label: "冷水机组",
        },
        {
          value: "3",
          label: "循环水泵",
        },
        {
          value: "4",
          label: "冷却塔",
        },
        {
          value: "5",
          label: "电动阀门",
        },
        {
          value: "6",
          label: "空调箱",
        },
        {
          value: "7",
          label: "变压器",
        },
      ],
      tData: [
        {
          a: "DIC21062314002255",
          b: "冷水机组巡检",
          c: "冷水机组",
          d: "",
          e: "2021-06-23 14:00:22",
          f: "liming",
        },
      ],
      //=============================================
      repairDialog: false,
      repairForm: {},
      tableData: [],
      //==============================================
      repairDialog1: false,
      repairForm1: {},
      subTable1: [
        {
          a: "1",
          b: "01",
          c: "1",
          d: "1",
          e: "1",
        },
        {
          a: "4",
          b: "04",
          c: "检查机组运行噪声",
          d: "运行声音或震动是否正常",
          e: "是/否",
        },
      ],
      subTable1Select: null, //声明一个变量保存选择的值
      //==============================================
      repairDialog2: false,
      repairForm2: {},
      repairDialog3: false,
      repairForm3: {},
    };
  },
  mounted() {
   
  },
  beforeUnmount() {
   
  },
  methods: {
    //获取设备类型
    getNewSelected(m) {
      this.type = m;
    },
    //清空筛选条件
    clearSelected() {
      // console.log("点击清空按钮");
      this.name = "";
      this.type = "";
    },
    //=============================================
    //"新增"弹窗清空功能
    repairDialogClose() {
      this.$refs.repairFormRef.resetFields();
      this.tableData = [];
    },
    //"新增"弹窗"步骤列表"当前选择值
    subTable1Selected(val) {
      console.log("选中项打印：", val);
      this.subTable1Select = val;
    },
    //"新增"弹窗"步骤列表"清除当前选择值
    repairDialog1Close(rows) {
      this.$refs.repairForm1Ref.resetFields();
      if (rows) {
        rows.forEach((row) => {
          this.$refs.subTable1Ref.toggleRowSelection(row);
        });
      } else {
        this.$refs.subTable1Ref.clearSelection();
      }
    },
    // “新增”窗口"步骤列表"后“关闭”按钮
    repairDialog1CalcBtn(rows) {
      this.$refs.repairForm1Ref.resetFields();
      if (rows) {
        rows.forEach((row) => {
          this.$refs.subTable1Ref.toggleRowSelection(row);
        });
      } else {
        this.$refs.subTable1Ref.clearSelection();
      }
      this.repairDialog1 = false;
    },
    //“新增”窗口"步骤列表"后“确认”按钮
    repairDialog1SureBtn() {
      this.repairDialog1 = false;
      this.tableData.push(...this.subTable1Select);
      console.log("this.tableData2", this.tableData2);
    },
    //=============================================
    //"编辑"弹窗清空功能
    repairDialog3Close() {
      this.$refs.repairForm3Ref.resetFields();
      this.tableData = [];
    },
    //“编辑”窗口"步骤列表"后“确认”按钮
    repairDialog3SureBtn() {
      this.repairDialog1 = false;
      this.tableData.push(...this.subTable1Select);
      console.log("this.tableData2", this.tableData2);
    },
    //==============================================
    //删除数据按钮
    del() {
      this.$confirm("此操作将永久删除该信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          // post("/airChannel/deleteAirChannel", { id: id }).then((res) => {
          //   // console.log(res);
          //   if (res.data.code == 200) {
          //     this.$message.success(res.data.data);
          //     this.getData();
          //   } else {
          //     this.$message.error(res.data.data);
          //   }
          // });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style lang="less" scoped>
@import "../opera.less";

.search_bar {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

/deep/ .el-dialog .el-select {
  width: 340px;
}

.row-1 {
  display: flex;
  justify-content: space-between;
  padding: 0 2vw 0 0;
}
</style>
